<template>
  <div>
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
     
            <Commentline @isreplyss="$emit('pingslhu',$event)" :content="item" v-for="(item,index) in list" :key="index"></Commentline>
          
    </van-list>
    

  </div>
</template>
<script>
import {pingl} from "../../../api/article"
import Commentline from "./Commentlines"
// console.log(pingl)
export default {
  props:{
      scrougID:{
          type:[String,Number,Object],
          required:true
      },
      type:{
        type:String,
        default:'a'
      }
  },
  components:{
      Commentline
  },
  name: "comments",

    data() {
        return {
            list: [],
            loading: false,
            finished: false,
            params:{
                type:this.type,
                source:'',
                offset:null,
                limit:10
            }

        };
    },

  methods:{
       async onLoad() {
           const {data} = await pingl({
               type:this.params.type,//评论类型，a-对文章(article)的评论，c-对评论(comment)的回复
               source:this.scrougID.toString(),//源id，文章id或评论id
               offset:this.params.offset,//获取评论数据的偏移量，值为评论id，表示从此id的数据向后取，不传表示从第一页开始读取数据
               limit:this.params.limit//获取的评论数据个数，不传表示采用后端服务设定的默认每页数据量

           })
        //    console.log(data)
           this.list.push(...data.data.results)
          //  console.log(data.data.results)
     
    //     // 加载状态结束
        this.loading = false;
        // console.log()
        this.$emit('pinglzongs',data.data.total_count)

    //     // 数据全部加载完成
        if (data.data.results.length ) {
          this.params.offset = data.data.last_id
        }else {
            this.finished = true
        }
        // console.log(this.list)
      // this.$emit('pinglist',11111111111111)
      this.$emit('paujgls',this.list)
    }
  }
};
</script>
<style scoped lang="less">
/deep/.van-cell__title {
    text-align: left;
}
</style>